; Badge-Dial V0.5 - display digit dialled in R7 (restart for next digit) ;Connect White(Common) to out-3 Red(Busy) to In-0, Blue(Pulse) to In-1 (nice 1:1 with plug) ; Initialiazation ; Output reg is all zeros, ie GND. Input Reg visible on Page0 00: "NOP" 01: "NOP" 02: MOV R0,#4 ; Set clock 03: MOV [#F1],R0 ; to 0.3ms 04: "NOP" 05: "NOP" 06: "NOP" 07: "NOP" 08: "NOP" 09: MOV R2,#1 ; debug, show we're here ; === MAIN === ; Start here scanning for a digit LoopNew: ; wait for Busy going low 0A: BIT IN,#0 ; Test bit 0 in R11 (OP-Y-Code is 0b1100) 0B: SKIP Z,1 ; Skip if Zero 0b10xx (ie Clear) xx=01 0C: JR LoopNew ; Back to loop if set 0D: MOV R2,#2 ; debug-show we're here 0E: "NOP" 0F: "NOP" ; Wait for pulse 10: MOV R7,#0 ; Counter of pulses LoopDigit: 11: BIT IN,#0 ; Have we stopped being busy? (Busy gone High) 12: SKIP Z,1 ; Skip if still busy : zero (0b10xx), ie low (skip=01) 13: JR Done ; No more pulses, done ( 30-14 = 1C ) 14: "NOP" 15: "NOP" 16: BIT IN,#1 ; A digit pulse? (Pulse High) 17: SKIP NZ,1 ; 18: JR LoopDigit ; (11-19=F8) not yet, try again 19: MOV PC,#05 ; Wait for debounce. Call Wait (addr 050) 1A: MOV JSR,#0 ; ->JSR->do the call 1B: INC R2 ;debug 1C: "NOP" 1D: "NOP" LoopEndPulse: 1E: BIT IN,#0 ; Have we stopped being busy? (Busy gone High) 1F: SKIP Z,1 ; Skip if still busy : zero (0b10xx), ie low (skip=01) 20: JR Done ; No more pulses, done ( 30-21 = 0F ) 21: BIT IN,#1 ; End of digit pulse? (Pulse Low) 22: SKIP Z,1 ; 23: JR LoopEndPulse ; (1E-24=FA) no, keep waiting 24: "NOP" 25: MOV PC,#05 ; Wait for debounce. Call Wait (addr 050) 26: MOV JSR,#0 ; ->JSR->do the call 27: INC R2 ;debug ; count one and go around 28: INC R7 29: JR LoopDigit ; (11-2A=E7) ... "NOPs" ... ;== Done: 30: MOV R2,#F ;debug 31: MOV R0,R7 32: CP R0,#10 ; is it the "0", 10 pulses? 33: SKIP NZ,1 34: MOV R7,#0 ; yes, store 35: "NOP" ; DEC R7 ; remove the extra tick, now it should be the number 36: "NOP" ; R7 now has the number ; === Work To come: ; Compare to some "secret digit" - show High/Low - or similar game ; OR just display the digit in readable on display 40: JR -1 ; "Halt" here ;==== Subroutines Wait: ; routine to wait for approx 5ms - ASSUMES clock is 0.3ms 50: MOV R3,#8 ; 8 times round the loop Waita: 51: DSZ R3 ; done it enough times? 52: JR Waita ; no, one more time 53: RET R0,#1 ; done (return value irellevant)